import Events from './index'
import Store from 'common/Store'
import Http from "common/Http";

export default class Event3 extends Events {
  static _ins: Event3
  static get instance(): Event3 {
    return this._ins || new Event3;
  }
  constructor() {
    super();
    Event3._ins = this
  }

  /**
   * 活动键值
   */
  protected _eventIndex: number = 2

  queryEvent(tag, params?) {
    var datas: any = {
      groupId: Events.groupId,
      actId: this.actId,
      token: Store.instance.map.userInfo.token
    }
    switch (tag) {
      case INFO:
        datas.rewardId = this.rewardId.last
        break;
      case JOIN:
        datas.step = params.step
        datas.rewardId = this.rewardId[params.step]
        break;
    }
    return Http.instance.getActivity(tag, datas).then(data => {
      if (data.code === 200) {
        var is200 = data.code === 200
        switch (tag) {
          case INFO:
            this.info = is200 ? data.state : null
            break;
          case CDKEYS:
            this.history = is200 ? data.state : []
        }
      }
      return data
    })
  }

}